package com.tanhua.server.controller;

import com.tanhua.model.db.UserInfo;
import com.tanhua.server.intercepror.UserHolder;
import com.tanhua.server.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 完善用户信息
     *  POST    /loginReginfo
     *  请求头：
     *     Authorization
     *  body参数：
     *     UserInfo
     *  返回值空
     */
    @PostMapping("/loginReginfo")
    public ResponseEntity loginReginfo(@RequestBody UserInfo userInfo) {
        //1、获取请求参数
        Long userId = UserHolder.getUserId();
        userInfo.setId(userId);
        //2、调用service
        userService.saveUserInfo(userInfo);
        //3、构造返回值
        return ResponseEntity.ok(null);
    }

    /**
     * 完善资料-上传头像
     *  POST   /loginReginfo/head
     *  请求头：
     *      Authorization
     *  文件参数：headPhoto
     *  返回值空
     */
    @PostMapping("/loginReginfo/head")
    public ResponseEntity head(MultipartFile headPhoto) throws IOException {
        //1、获取请求参数
        Long userId = UserHolder.getUserId();
        //2、调用service
        userService.head(userId,headPhoto);
        //3、构造返回值
        return ResponseEntity.ok(null);
    }


}
